package com.easywan.service.impl;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.easywan.dao.ToolsClothesSizeMapper;
import com.easywan.pojo.IResult;
import com.easywan.pojo.IResultSupport;
import com.easywan.service.IToolsClothesSizeService;
import com.easywan.vo.ToolsClothesSize;

@Service("toolsClothesSizeService")
public class ToolsClothesSizeServiceImpl implements IToolsClothesSizeService{
	Logger logger = Logger.getLogger(ToolsClothesSizeServiceImpl.class);
	@Autowired
	ToolsClothesSizeMapper mapper;
	@Transactional
	public IResult getSize(Integer height, Integer weight, Integer people, Integer type) {
		Integer resultCode = IResult.SUCCESS_CODE;
		ToolsClothesSize clothesSize = new ToolsClothesSize();
		clothesSize.setHeight(height);
		clothesSize.setType(type);
		clothesSize.setWeight(weight);
		clothesSize.setPeople(people);
		String size = null;
		try {
			size = ToolsClothesSize.getSize(weight, height, people, type);
		} catch (Exception e) {
			e.printStackTrace();
			size = e.getMessage();
			resultCode = IResult.FAILT_CODE;
		}
		if(mapper.insert(clothesSize) == 0){
			logger.error("添加数据失败");
			logger.error(clothesSize);
		}
		return IResultSupport.buildResult(resultCode, size,clothesSize);
	}
	
}
